package genetic;

import genetic.treenodes.Addition;
import genetic.treenodes.Constant;
import genetic.treenodes.Division;
import genetic.treenodes.Multiplication;
import genetic.treenodes.Subtraction;
import genetic.treevisualizer.METreeBranchRenderer;
import genetic.treevisualizer.METreeNodeRenderer;
import genetic.treevisualizer.TreeVisualizer;

import java.awt.Color;
import java.io.File;
import java.util.ArrayList;

public class T05_crossover {

	public static void main(String[] args) {
		TreeVisualizer tv = new TreeVisualizer();
		tv.setTreeBranchRenderer(new METreeBranchRenderer());
		tv.setTreeNodeRenderer(new METreeNodeRenderer());
		tv.setBranchStartWidth(10.0);
		tv.setArenaColor(Color.black);
		tv.setSide(550);
		tv.setCircleDiminishFactor(0.75);
		
		ArrayList<GPTreeNode> functionSet = new ArrayList<GPTreeNode>();
		ArrayList<GPTreeNode> terminalSet = new ArrayList<GPTreeNode>();
		
		functionSet.add(new Addition());
		functionSet.add(new Subtraction());
		functionSet.add(new Multiplication());
		functionSet.add(new Division());
		
		terminalSet.add(new Constant(11.11));
		terminalSet.add(new Constant(22.22));
		
		GeneticProgram gp = new GeneticProgram(functionSet, terminalSet);
		
		gp.createRandom(10, 1);
		
		GeneticProgram gp2 = gp.clone();

		tv.writeImageFile(tv.renderTree(gp.getRoot()), new File("T05_gp.png"));
		tv.writeImageFile(tv.renderTree(gp2.getRoot()), new File("T05_gp2.png"));
		
		GeneticProgram gp3 = GeneticProgram.crossover(gp, gp2);
		
		tv.writeImageFile(tv.renderTree(gp3.getRoot()), new File("T05_gp3.png"));
	}
}
